'use strict';

module.exports = {
  up: (queryInterface, Sequelize) => {
    /*
      Add altering commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.createTable('users', { id: Sequelize.INTEGER });
    */
    const { INTEGER, TEXT, DATE, STRING, BOOLEAN } = Sequelize;
    return queryInterface.createTable('codes', {
      code: { type: INTEGER, primaryKey: true, autoIncrement: true },
      user: {
        type: INTEGER,
        references: {
          model: 'users',
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE',
      },
      client_id: STRING(100),
      redirect_uri: TEXT,
      scope: TEXT,
      valid: BOOLEAN,
      created_at: DATE,
      updated_at: DATE,
    });
  },

  down: queryInterface => {
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */
    return queryInterface.dropTable('codes');
  },
};
